/*
 * Created: Author: Aléx Carvalho / Date: Feb 25, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-05-15 00:29:31 +0000 (Fri, 15 May 2015) $
 */
package com.cpm.wrapper;

import com.cpm.aggregate.Attribute;
import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class Position implements Attribute<Short>, Comparable<Position> {
    
    @Column(nullable = false)
    private Short position;

    public Position() {
    }

    public Position(Integer position) {
        this.position = position.shortValue();
    }
    
    public Position(Short position) {
        this.position = position;
    }

    public Position(Position position) {
        this.position = position.position;
    }

    public Position increment(){
        return new Position((short)(position+1));
    }
    
    public Position decrement(){
        return new Position((short)(position-1));
    }
    
    public boolean smaller(Position o){
        return compareTo(o) == -1;
    }

    public boolean larger(Position o){
        return compareTo(o) == 1;
    }
    
    @Override
    public Short getValue() {
        return position;
    }

    @Override
    public int compareTo(Position o) {
        return position.compareTo(o.position);
    }

    @Override
    public String toString() {
        return position.toString();
    }
}